package com.moli.iov.open.service.impl;

import com.moli.iov.alarm.model.dto.req.AlarmInfoThirdDto;
import com.moli.iov.alarm.model.po.AlarmInfo;
import com.moli.iov.alarm.remote.IAlarmThirdRemoteService;
import com.moli.iov.open.model.vo.req.AlarmInfoVo;
import com.moli.iov.open.service.IAlarmFacadeService;
import com.moli.iov.rest.RestResponse;
import com.moli.iov.util.CommonUtils;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 报警业务
 * </p>
 *
 * @author zql
 * @since 2019/9/27 11:01
 */
@Slf4j
@Service
public class AlarmFacadeServiceImpl implements IAlarmFacadeService {

  @Reference(group = "${service.group}", check = false)
  private IAlarmThirdRemoteService alarmThirdRemoteService;

  /**
   * 失联车辆报警列表
   * @param alarmInfoVo
   * @return
   */
  @Override
  public RestResponse<List<AlarmInfo>> listOfflineAlarms(AlarmInfoVo alarmInfoVo) {
    return alarmThirdRemoteService.listOfflineAlarms(convertDto(alarmInfoVo));
  }

  /**
   * 里程异变报警列表
   * @param alarmInfoVo
   * @return
   */
  @Override
  public RestResponse<List<AlarmInfo>> listMileageExAlarms(AlarmInfoVo alarmInfoVo) {
    return alarmThirdRemoteService.listMileageExAlarms(convertDto(alarmInfoVo));
  }

  /**
   * 围栏报警
   * @param alarmInfoVo
   * @return
   */
  @Override
  public RestResponse<List<AlarmInfo>> listFenceAlarms(AlarmInfoVo alarmInfoVo) {
    return alarmThirdRemoteService.listFenceAlarms(convertDto(alarmInfoVo));
  }

  /**
   * 组装DTO
   * @param alarmInfoVo
   * @return
   */
  private AlarmInfoThirdDto convertDto(AlarmInfoVo alarmInfoVo){
    AlarmInfoThirdDto alarmInfoThirdDto = new AlarmInfoThirdDto();
    CommonUtils.copyProperties(alarmInfoVo, alarmInfoThirdDto);
    return alarmInfoThirdDto;
  }


}
